﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Windows.Forms.DataVisualization.Charting;
using AntdUI;
using ChineseCalendar;
using YfShlErp.BLL1;
using YfShlErp.Model;
using static System.Windows.Forms.VisualStyles.VisualStyleElement.Rebar;
using YfShlErp.Properties;

namespace YfShlErp
{
    public partial class MainForm : Window
    {
        private InquirySellersDataBLL inquiry1 = new InquirySellersDataBLL();

        private BindingSource SellersData_bindingSource = new BindingSource();

        [DllImport("user32.dll")]
        private static extern int ReleaseCapture();

        [DllImport("user32.dll")]
        private static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam);

        public MainForm()
        {
            InitializeComponent();
            timer1 = new Timer();
            timer1.Interval = 1000;
            timer1.Tick += Timer1_Tick;
            timer1.Start();
            dataGridView1.AutoGenerateColumns = false;
            initialHomeShow();
        }

        public void initialHomeShow()
        {
            var price = inquiry1.GetFruitPrice();
            textBox1.Text = price[0].BigFP.ToString();
            textBox2.Text = price[0].GreenFP.ToString();
            textBox3.Text = price[0].smallFP.ToString();
            textBox4.Text = price[0].MiddleFP.ToString();
        }

        private void Timer1_Tick(object sender, EventArgs e)
        {
            labelTime.Text = "当前时间 " + DateTime.Now.ToString("HH :mm :ss");
        }

        private void panel1_MouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                ReleaseCapture();
                SendMessage(this.Handle, 0x00A1, 0x0002, 0);
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Dispose();
            Application.Exit();
        }

        private void menu1_SelectChanged(object sender, MenuSelectEventArgs e)
        {
            tabControl1.SelectedIndex = int.Parse(e.Value.ID);
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.WindowState = FormWindowState.Minimized;
        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
        }

        private void uploadPictures_Click(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();
            openFileDialog.Filter = "Image Files|*.jpg;*.jpeg;*.png;*.bmp;*.gif";

            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                string filePath = openFileDialog.FileName;

                pictureBox1.Image = System.Drawing.Image.FromFile(filePath);
                //用全局
                byte[] imageBytes = File.ReadAllBytes(filePath);

                uploadPictures.Hide();
            }
        }

        private void SendBtn_Click(object sender, EventArgs e)
        {
            string text = richTextBox1.Text;
        }

        private void MainForm_Load(object sender, EventArgs e)
        {
            // 初始化数据
            string[] days = { "周一", "周二", "周三", "周四", "周五", "周六", "周日" };
            int[] harvest = { 120, 150, 90, 200, 180, 210, 80 };

            // 配置图表
            chart1.Titles.Add("一周收果量统计");
            chart1.ChartAreas[0].AxisX.Title = "星期";
            chart1.ChartAreas[0].AxisY.Title = "收果量 (公斤)";
            chart1.ChartAreas[0].AxisX.Interval = 1;

            // 添加数据系列
            chart1.Series.Clear();
            chart1.Series.Add("收果量");
            chart1.Series["收果量"].ChartType = SeriesChartType.Column;
            chart1.Series["收果量"].IsValueShownAsLabel = true;

            // 绑定数据
            for (int i = 0; i < days.Length; i++)
            {
                chart1.Series["收果量"].Points.AddXY(days[i], harvest[i]);
            }
        }

        private void EnterBtn_Click(object sender, EventArgs e)
        {
            SellerinformationEntryForm sellerinformationEntryForm = new SellerinformationEntryForm();
            sellerinformationEntryForm.ShowDialog();
        }

        private void inquiry_TextChanged(object sender, EventArgs e)
        {
        }

        private void inquiry_Click(object sender, EventArgs e)
        {
            inquiry.Text = "";
        }

        private void InquiryBtn_Click(object sender, EventArgs e)
        {
            if (datePicker1.Text == null || datePicker1.Text == "")
            {
                var data1 = (List<SellerFruit>)inquiry1.GetSellersData(inquiry.Text);
                SellersData_bindingSource.DataSource = data1;
                dataGridView1.DataSource = SellersData_bindingSource;
                return;
            }

            List<SellerFruit> data = (List<SellerFruit>)inquiry1.GetSellersData(inquiry.Text, DateTime.Parse(datePicker1.Text));
            SellersData_bindingSource.DataSource = data;
            dataGridView1.DataSource = SellersData_bindingSource;
        }

        private void restartBtn_Click(object sender, EventArgs e)
        {
            pictureBox1.Image = null;
            uploadPictures.Show();
        }

        private void tabPage4_Click(object sender, EventArgs e)
        {
            inquiry.Text = "请输入名字或手机号";
        }

        private BindingSource Binding = new BindingSource();

        private void button3_Click(object sender, EventArgs e)
        {
            List<Tss> tsses = new List<Tss>()
            {
                 new Tss()
                 {
                      Id = 1,
                       Name ="1"
                 },
                  new Tss()
                 {
                      Id = 2,
                       Name ="2"
                 }
            };
            List<SellerFruit> sellerFruits = new List<SellerFruit>()
            {
                 new SellerFruit()
                 {
                      FruitType = "1",
                       SellerName = "1",
                 },
                    new SellerFruit()
                 {
                      FruitType = "1",
                       SellerName = "1",
                 }
            };
            Binding.DataSource = sellerFruits;
            dataGridView1.DataSource = Binding; //
            //  var ewq = dataGridView1.Rows[0].Cells[0].Value;
        }
    }

    public class Tss
    {
        //
        public int Id { get; set; }

        public string Name { get; set; }
    }
}